/**
 * 部门管理初始化
 */
var CashDailyReport = {
    id: "CashDailyReportTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CashDailyReport.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: '日期', field: 'rechargeTime',align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                var reg = /-0/g;
                var regs = /-/g;
                value = value.replace(reg, '-');
                value = value.replace(regs, '.');
                return value;
            }
        },
        {title: '日总收入', field: 'totalDailyIncome',align: 'center', valign: 'middle'},
        {title: '现金', field: 'cash',align: 'center', valign: 'middle'},
        {title: '随行付', field: 'followUp',align: 'center', valign: 'middle'},
        {title: '华夏刷卡', field: 'huaXiaCard',align: 'center', valign: 'middle'},
        {title: '医保', field: 'medicalInsurance',align: 'center', valign: 'middle'},
        {title: '美团', field: 'meiTuan',align: 'center', valign: 'middle'},
        {title: '荣华', field: 'huaRong',align: 'center', valign: 'middle'},
        {title: '百度钱包', field: 'baiduPurse',align: 'center', valign: 'middle'},
        {title: '华银百汇扫码', field: 'huaYinBaiHui',align: 'center', valign: 'middle'},
        {title: '糯米', field: 'glutinousRice',align: 'center', valign: 'middle'},
        {title: '天猫', field: 'tmall',align: 'center', valign: 'middle'},
        {title: '备注', field: 'remark',align: 'center', valign: 'middle'},
    ]
    return columns;
};

CashDailyReport.downLoad = function () {
    var queryData = {};
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    var param = parseParam(queryData);
    location.href = Feng.ctxPath + '/cashDailyReport/cashDailyReportExport?' + param;
}

/**
 * 统计总人数
 */
CashDailyReport.total = function () {
    //获取跟踪人数
    var param1 = $("#startTime").val();  //开始到店时间
    var param2 = $("#endTime").val();   //结束到店时间
    $.ajax({
        type: "GET",
        url: Feng.ctxPath + "/cashDailyReportTwo/total",
        data: {
            param1: param1, param2: param2
        },
        dataType: "json",
        success: function (data) {
            $("#total").html(data[0].countNum);//总人数
        }
    });
};


CashDailyReport.inquire = function () {
    CashDailyReport.search()
}

/**
 * 查询预约客户列表
 */
CashDailyReport.search = function () {
    CashDailyReport.table.refresh({query: CashDailyReport.formParams()});


};

CashDailyReport.searchRevisit = function () {
    CashDailyReport.table.refresh({query: CashDailyReport.formParamss()});
};
var myDate = new Date();
var month;
var day;
if ((myDate.getMonth() + 1) < 10) {
    month = "0" + (myDate.getMonth() + 1);
} else {
    month = "" + (myDate.getMonth() + 1);
}
if (myDate.getDate() < 10) {
    day = "0" + myDate.getDate();
} else {
    day = "" + myDate.getDate();
}
CashDailyReport.formParamss = function () {
    var queryData = {};
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    return queryData;
}

//把对象拼接成URL的键值对参数param1=value1&param2=value2
var parseParam = function (param) {
    var paramStr = "";

    $.each(param, function (i) {
        paramStr += '&' + getSingleData(param, i);
    });
    return paramStr.substr(1);
};

var getSingleData = function (param, key) {
    return key + "=" + param[key];
}

CashDailyReport.downLoad = function () {
    var queryData = {};
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    var param = parseParam(queryData);
    location.href = Feng.ctxPath + '/cashDailyReport/cashDailyReportExport?' + param;
}

CashDailyReport.resetSearch = function () {
    document.getElementById("startTime").value = myDate.getFullYear() + "-" + month + "-" + day ;
    document.getElementById("endTime").value = myDate.getFullYear() + "-" + month + "-" + day ;
    CashDailyReport.search();
};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
CashDailyReport.formParams = function () {
    var queryData = {};
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    return queryData;
}

$(function () {
    document.getElementById("startTime").value = myDate.getFullYear() + "-" + month + "-" + day ;
    document.getElementById("endTime").value = myDate.getFullYear() + "-" + month + "-" + day ;
    var defaultColunms = CashDailyReport.initColumn();
    var table = new BSTable(CashDailyReport.id, "/cashDailyReport/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(CashDailyReport.formParams);
    CashDailyReport.table = table.init();
    CashDailyReport.search();

    //采用定时器监听 时间内容是否变化
    var startTimeTwo = $("#startTime").val();
    var endTimeTwo = $("#endTime").val();

    setInterval(
        function () {//定时执行方法内容
            if ($("#startTime").val() != startTimeTwo || $("#endTime").val() != endTimeTwo) {//如果时间发生变化，就触发查询事件
                CashDailyReport.search()
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                startTimeTwo = $("#startTime").val();
                endTimeTwo = $("#endTime").val();
            }

        }, 500);
});
